package com.example.dto;

import com.example.constant.ResponseCode;

public class Response<T> {

    private String errcode;
    private String errmsg;
    private boolean success;
    private T data;

    public Response() {}

    public Response(T data) {
        this.data = data;
    }

    public Response(ResponseCode responseCode) {
        this.errcode = responseCode.getCode();
        this.errmsg = responseCode.getMessage();
    }

    public Response(String errcode, String errmsg, T data) {
        this.errcode = errcode;
        this.errmsg = errmsg;
        this.data = data;
    }

    public Response returnSuccess(){
        this.errcode = ResponseCode.SUCCESS.getCode();
        this.errmsg = ResponseCode.SUCCESS.getMessage();
        return this;
    }

    public Response returnFailure(){
        this.errcode = ResponseCode.FAIL.getCode();
        this.errmsg = ResponseCode.FAIL.getMessage();
        return this;
    }

    public String getErrcode() {
        return errcode;
    }

    public void setErrcode(String errcode) {
        this.errcode = errcode;
    }

    public String getErrmsg() {
        return errmsg;
    }

    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        if(ResponseCode.SUCCESS.getCode().equals(this.errcode)){
            success = true;
        }
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }
}
